import os
import sys

CEL_BASE_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0,os.path.join(CEL_BASE_DIR,"../ihome"))


import time
from celery import Celery
app = Celery('mycelery',broker='redis://127.0.0.1:6379/14',backend='redis://127.0.0.1:6379/15')
@app.task(bind=True)
def send_sms_code(self,mobile,sms_code):
    from libs.yuntongxun.sms import CCP
    time.sleep(3)
    ccp = CCP()
    try:
        # 成功是0，失败是-1
        res = ccp.send_template_sms(mobile, [sms_code, 5], 1)
    except Exception as e:
        print(e)
        res = -1
    if res == -1:
        # 如果res结果是-1，就每间隔3s，重发一次，总共重发3次
        self.retry(countdown=3,max_retries=3,exc=Exception('短信发送失败'))
